import { BaseWindow } from "../../../component/window/BaseWindow";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { PetUpgradeTipPanel } from "./PetUpgradeTipPanel";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { PetColor } from "./info/PetColor";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { PetUtil } from "./info/PetUtil";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { Cache } from "../../cache/Cache";
import { BuyAlert } from "./BuyAlert";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class PetBatchUpgradeWindow
    
    export  class PetBatchUpgradeWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this.setSize(255, 210);
            this.title = Language.getString(54428);
            this.titleHeight = 28;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._cSprite = new Object /* flash.display.Sprite */();
            this._cSprite.x = 17;
            this._cSprite.y = 39;
            this.addChild(this._cSprite);
            ObjCreate.createBg(0, 0, 220, 160, this._cSprite);
            ObjCreate.createBg(0, 0, 100, 28, this._cSprite, ImagesConst.TileBg);
            this._nameTxt = ObjCreate.createTextField("", 20, 5, 100, 20, this._cSprite);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createTextField(Language.getString(54429), 110, 5, 100, 20, this._cSprite);
            this._spiritTxt = ObjCreate.createTextField("", 150, 5, 50, 20, this._cSprite);
            this._upgradeTipPanel = new PetUpgradeTipPanel();
            this._upgradeTipPanel.x = 180;
            this._upgradeTipPanel.y = 0;
            this._cSprite.addChild(this._upgradeTipPanel);
            ObjCreate.createTextField(Language.getString(54422), 20, 45, 100, 20, this._cSprite, GlobalStyle.textFormat6);
            this._numInput = ObjCreate.createGTextInput(80, 40, 35, 20, this._cSprite);
            this._numInput.text = "10";
            this._numInput.maxChars = 2;
            this._numInput.restrict = "0-9";
            this._haveTxt = ObjCreate.createTextField("", 120, 45, 100, 20, this._cSprite, GlobalStyle.textFormat5);
            ObjCreate.createTextField(Language.getString(54430), 20, 75, 100, 20, this._cSprite, GlobalStyle.textFormat6);
            this._targetInput = ObjCreate.createGTextInput(80, 70, 35, 20, this._cSprite);
            this._targetInput.maxChars = 2;
            this._targetInput.restrict = "0-9";
            ObjCreate.createTextField(Language.getString(54424), 120, 75, 100, 20, this._cSprite, GlobalStyle.textFormat6);
            this._upgradeBtn = ObjCreate.createGButton(Language.getString(54425), 70, 100, 70, 24, this._cSprite, "ButtonSpecial");
            this._upgradeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onUpgradeBtnClickHandler);
            this._autoBuyCheckBox = ObjCreate.createCheckBox(Language.getString(54426), 30, 130, 150, 28, this._cSprite);
            return;
        }

        public updateBySPetInfo(arg1: SPetInfo): void
        {
            var loc2=null;
            var loc3=null;
            this._petInfo = arg1;
            var loc1=6;
            if (arg1) 
            {
                this._nameTxt.htmlText = PetColor.getColorName(arg1);
                this._spiritTxt.htmlText = HTMLUtil.addColor(arg1.spirit.toString(), PetUtil.getSpiritTitleColor(arg1.spirit));
                loc2 = PetUtil.getSpiritTitle(arg1.spirit);
                if (loc2) 
                {
                    if (loc3 = PetUtil.getSpiritTitleByGrade(loc2.grade + 1)) 
                    {
                        loc1 = loc3.needNum;
                    }
                }
                this._targetInput.text = loc1.toString();
                this._upgradeTipPanel.updateByPet(false, arg1, false);
            }
            return;
        }

        public updateAmount(arg1: int): void
        {
            this._haveAmount = arg1;
            this._haveTxt.text = Language.getStringByParam(54431, arg1);
            return;
        }

        public updateCostProp(arg1: ShopItemInfo): void
        {
            this._costProp = arg1;
            return;
        }

        public selectCb(arg1: Boolean): void
        {
            this._autoBuyCheckBox.selected = arg1;
            return;
        }

        public getCb(): GCheckBox
        {
            return this._autoBuyCheckBox;
        }

        /* internal  */onUpgradeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc5=false;
            var loc1=int(this._targetInput.text);
            var loc2=int(this._numInput.text);
            var loc3;
            if ((loc3 = this._haveAmount + int(Cache.instance.role.money.gold / this._costProp.tshopSell.price)) > 99) 
            {
                loc3 = 99;
            }
            if (loc1 > 20) 
            {
                this._targetInput.text = "20";
            }
            var loc4=this._autoBuyCheckBox.selected;
            if (loc2 > loc3) 
            {
                this._numInput.text = loc3.toString();
            }
            if (loc2 > this._haveAmount) 
            {
                if (loc4) 
                {
                    if (loc5 = BuyAlert.checkMoney(EPrictUnit._EPriceUnitGold, (loc2 - this._haveAmount) * this._costProp.tshopSell.price)) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.PetBatchUpgradeSpirit, {"uid": this._petInfo.uid, "isAutoBuy": loc4, "num": loc2, "target": loc1}));
                    }
                    else 
                    {
                        return;
                    }
                }
                else 
                {
                    this._costProp.buyNum = loc2 - this._haveAmount;
                    BuyAlert.showByShopItemInfo(this._costProp);
                }
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetBatchUpgradeSpirit, {"uid": this._petInfo.uid, "isAutoBuy": loc4, "num": loc2, "target": loc1}));
            }
            return;
        }

        /* internal */ /* var */_cSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_spiritTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_numInput: GTextInput;

        /* internal */ /* var */_targetInput: GTextInput;

        /* internal */ /* var */_haveTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_upgradeBtn: GButton;

        /* internal */ /* var */_autoBuyCheckBox: GCheckBox;

        /* internal */ /* var */_upgradeTipPanel: PetUpgradeTipPanel;

        /* internal */ /* var */_petInfo: SPetInfo;

        /* internal */ /* var */_haveAmount: int;

        /* internal */ /* var */_costProp: ShopItemInfo;
    }
